const express = require('express');
const router = express.Router();
const { formatResponseBody } = require("../utils/tools");
const blogTypeSer = require("../service/blogTypeService");

// 获取所有分类
router.get("/", async (req, res, next) => {
    const data = await blogTypeSer.getAllBlogType();
    res.send(formatResponseBody({ data }));
})

// 获取单个分类
router.get("/:id", async (req, res, next) => {
    const data = await blogTypeSer.getOneBlogType(req.params.id);
    res.send(formatResponseBody({ data }));
})

// 添加一个分类
router.post("/", async (req, res, next) => {
    const data = await blogTypeSer.addOneBlogType(req.body);
    res.send(formatResponseBody({ data }))
})

// 删除一个分类
router.delete("/:id", async (req, res, next) => {
    const data = await blogTypeSer.deleteOnBlogType(req.params.id);
    res.send(formatResponseBody({ data }));
})

// 修改一个分类
router.put("/:id", async (req, res, next) => {
    const data = await blogTypeSer.changeOneBlogType(req.body, req.params.id);
    res.send(formatResponseBody({ data }));
})

module.exports = router;